function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var e = t(require("../../utils/api2")), i = t(require("../../utils/util"));

Component({
    properties: {
        initdata: {
            type: Object,
            observer: function(t) {
                var e = t.sid, i = t.navid, r = t.catid, d = t.cid, a = t.modid, o = void 0 === a ? 3 : a, s = t.op, n = void 0 === s ? "view" : s;
                this.setData({
                    initdata: t
                }), d && this.getProductData({
                    sid: e,
                    navid: i,
                    catid: r,
                    cid: d,
                    modid: o,
                    op: n
                });
            }
        }
    },
    data: {
        initdata: {},
        slider: {
            sliderStatus: !1,
            activeIndex: 0
        },
        product: {},
        order: {
            num: 1,
            repertory: 1,
            type: "",
            typeid: null,
            price: 0
        },
        defaultCover: "/images/default/logo.png"
    },
    methods: {
        getProductData: function(t) {
            var i = this;
            e.default.site.content.view({
                data: t,
                desc: "获取商品数据"
            }).then(function(t) {
                var e = i.data, r = e.slider.activeIndex, d = e.order, a = t.extras[r], o = a.repertory, s = a.id, n = a.price, l = a.type;
                d = Object.assign({}, d, {
                    repertory: o,
                    type: l,
                    price: n.toFixed(2),
                    typeid: s
                }), i.setData({
                    product: t,
                    order: d
                }), i.toggleSlider();
            });
        },
        toggleSlider: function() {
            var t = this.data.slider.sliderStatus;
            this.sliderToggleAnimate = this.sliderToggleAnimate || wx.createAnimation({
                duration: 200,
                timingFunction: "linear"
            }), this.sliderToggleAnimate.bottom(t ? "-1000rpx" : 0).step(), this.setData({
                "slider.detailAnimation": this.sliderToggleAnimate.export(),
                "slider.sliderStatus": !t,
                "order.num": 1,
                "slider.activeIndex": 0
            });
        },
        selectProductType: function(t) {
            var e = t.currentTarget.dataset.index, i = this.data.slider.activeIndex, r = this.data.product.extras[e], d = r.repertory, a = r.type, o = r.price, s = r.id;
            i !== e && this.setData({
                "slider.activeIndex": e,
                "order.repertory": d,
                "order.price": o.toFixed(2),
                "order.type": a,
                "order.typeid": s,
                "order.num": d ? 1 : 0
            });
        },
        updateOrderCount: function(t) {
            var e = t.currentTarget.dataset.type, i = this.data.order, r = i.num, d = i.repertory;
            "add" === e ? r < d && r++ : r && r--, this.setData({
                "order.num": +r
            });
        },
        productNumBlur: function(t) {
            var e = t.detail.value, i = this.data.order.repertory;
            e > i && this.showSliderToast("商品库存不足"), this.setData({
                "order.num": e > i ? i : +e
            });
        },
        showSliderToast: function(t) {
            var e = this;
            this.setData({
                sliderToastContent: t,
                showSliderToast: !0
            }), setTimeout(function() {
                e.setData({
                    showSliderToast: !1
                });
            }, 1500);
        },
        addToCart: function(t) {
            var r = this, d = this.data.product, a = d.catid, o = d.content, s = o.sid, n = o.navid, l = o.cid, u = this.data.order, c = u.num, p = u.typeid, h = t.detail.formId, m = getApp().globalData.appid;
            c ? (e.default.site.shopcart.add({
                data: {
                    appid: m,
                    sid: s,
                    num: c,
                    model: "product",
                    params: {
                        navid: n,
                        catid: a,
                        cid: l,
                        typeid: p
                    }
                }
            }).then(function(t) {
                wx.showToast({
                    title: "已加入购物车"
                }), r.toggleSlider();
            }), i.default.collectFormid(h)) : this.showSliderToast("请至少添加一件商品到购物车");
        }
    }
});